package cn.hsa.xxx.bookData.dto;

import cn.hsa.xxx.api.dto.BookInventoryDTO;
import cn.hsa.xxx.bookData.entity.BookInventoryDO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;


@Component
public class BookInventoryDTOConverter {

    /**
     * Convert BookInventoryDTO to BookInventoryDO
     *
     * @param bookInventoryDTO
     * @return
     */
    public BookInventoryDO convertToBookInventoryDO(BookInventoryDTO bookInventoryDTO) {
        if (bookInventoryDTO == null) {
            return null;
        }
        BookInventoryDO bookInventoryDO = new BookInventoryDO();

        //BookInventoryDO.setId(BookInventoryDTO.getId());
        //BookInventoryDO.setName(BookInventoryDTO.getName());
        //BookInventoryDO.setSex(BookInventoryDTO.getSex());
        //BookInventoryDO.setAddr(BookInventoryDTO.getAddr());

        //性能略差，但使用方便
        BeanUtils.copyProperties(bookInventoryDTO, bookInventoryDO);

        return bookInventoryDO;
    }

    /**
     * Convert BookInventoryDO to BookInventoryDTO
     *
     * @param bookInventoryDO
     * @return
     */
    public BookInventoryDTO convertToBookInventoryDTO(BookInventoryDO bookInventoryDO) {
        if (bookInventoryDO == null) {
            return null;
        }

        BookInventoryDTO bookInventoryDTO = new BookInventoryDTO();

        //BookInventoryDTO.setId(BookInventoryDO.getId());
        //BookInventoryDTO.setName(BookInventoryDO.getName());
        //BookInventoryDTO.setSex(BookInventoryDO.getSex());
        //BookInventoryDTO.setAddr(BookInventoryDO.getAddr());

        //性能略差，但使用方便
        BeanUtils.copyProperties(bookInventoryDO, bookInventoryDTO);

        return bookInventoryDTO;
    }
}
